package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.UserInfoMapper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = UserInfoService.class)
@Transactional
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public void add(UserInfo userInfo) {
        userInfoMapper.add(userInfo);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //直接使用分页插件 (告诉mybatis要分页了)
        Page page =  PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //写一个查询sql
        List<UserInfo> userInfos = userInfoMapper.findPage(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),userInfos);


    }

    @Override
    public void delete(Integer id) {
        userInfoMapper.delete(id);

    }
}
